﻿@model Von.Web.Models.CommentPartialModel
@{
    List<Von.Web.Structs.CommentInfo> Comments = await (new Von.Web.Tasks.CommentTask()).ListByComment<Von.Web.Structs.CommentInfo>(Model.Kind, Model.Linker);
}
@* ---------------- Comment ----------------
    点评值	Evaluation		int
    关注数	ConcernCount	bool
    支持数	SupportCount	bool
    差评数	OpposeCount		bool *@
@{
    int sumEvaluation = 0;
    int sumConcernCount = 0;
    int sumSupportCount = 0;
    int sumOpposeCount = 0;
    foreach (var c in Comments)
    {
        sumEvaluation += c.Evaluation;
        sumConcernCount += c.Concern ? 1 : 0;
        sumSupportCount += c.Support ? 1 : 0;
        sumOpposeCount += c.Oppose ? 1 : 0;
    }
}
<div id="comment-editor" class="comment-editor">
    <div class="header">
        <span class="title">网友评论</span>
        <span class="count">
            <em>@Comments.Count</em>条评论<span> | </span>
            <em>@sumConcernCount</em>人关注<span> | </span>
            <em>@sumSupportCount</em>人赞<span> | </span>
            <em>@sumSupportCount</em>人反对<span> | </span>
            平均得分<em>@string.Format("{0:0.0}", Comments.Count == 0 ? 0 : sumEvaluation / Comments.Count)</em>
        </span>
    </div>
    <div class="sender">
        <div class="inner">
            <textarea id="CommentContent" style="width: 100%; background: none;" placeholder="我有话要说..." value=""></textarea>
        </div>
        <div class="user">
            @if (User.Identity.IsAuthenticated)
            {
                <a href="" target="_blank"><img src="/Service/UserIcon/@User.Claims.FirstOrDefault(c => c.Type == System.Security.Claims.ClaimTypes.NameIdentifier).Value" style="border-radius:16px;margin-right:5px;width:32px;height:32px;" /></a>
            }
            else
            {
                <a href="" target="_blank"><img src="~/images/guest.png" /></a>
            }
        </div>
    </div>
    <div class="input-group">
        <div class="input-group-addon" title="我给打个分">
            <div class="rate-content">
                <input type="radio" name="rate" value="1">
                <input type="radio" name="rate" value="2">
                <input type="radio" name="rate" value="3">
                <input type="radio" name="rate" value="4">
                <input type="radio" name="rate" value="5">
            </div>
        </div>
        <input id="commentEmail" type="text" class="form-control" placeholder="需要回复到的email" value="@(User.Identity.IsAuthenticated ? @User.Claims.FirstOrDefault(c => c.Type == System.Security.Claims.ClaimTypes.Email).Value : "")" />
        <span class="input-group-addon"><a class="btn-default" onclick="publishComment(this)">发布</a></span>
    </div>
</div>
<div class="comment-editor" @*style="@(Model.Comments.Count > 3 ? "max-height:230px;" : "")"*@>
    @foreach (var comment in Comments)
    {
        <div class="sender">
            <div class="inner">
                <div class="txt" comment-type="itemTxt">
                    @comment.Content
                </div>
            </div>
            <div class="user">
                <a href="" target="_blank"><img src="/Service/UserIcon/@comment.Publisher.ToString()" style="border-radius:16px;margin-right:5px;width:32px;height:32px;" /></a>
            </div>
        </div>
        if (!comment.Replyer.Equals(Guid.Empty))
        {
            <div class="relay">
                <div class="inner">
                    <div class="txt" comment-type="itemTxt">
                        @comment.ReplyContent
                    </div>
                </div>
                <div class="user">
                    <a href="" target="_blank"><img src="/Service/UserIcon/@comment.Replyer.ToString()" style="border-radius:16px;margin-right:5px;width:32px;height:32px;" /></a>
                </div>
            </div>
        }
        <hr />
    }
</div>
<script>
    function publishComment(btn) {
        var c = $(".rate-content input:checked");
        $(btn).hide();
        var data = {
            LinkIdx: "@Model.Linker",
            Kind: "@Model.Kind",
            Summary: "@Model.Summary",
            Evaluation: c.length < 1 ? 0 : c.val(),
            Email: $("#commentEmail").val(),
            Concern: 1, Support: 1, Oppose: 1,
            Content: $("#CommentContent").val(),
            ReplyContent: $("#ReplyContent").val()
        };
        AjaxPostData("@Url.Ajax("/home/CommentPublish")", data, function (data) { alert("评论提交成功，管理人员会关注您的评论，谢谢！"); $(btn).show(); });
    }
</script>